<?php require_once("header.php");?>
<?php
	if(isset($_GET['rid']) && is_numeric($_GET['rid'])):
		$rid = $_GET['rid'];
	else:
		$rid = -1;
	endif;
?>
<?php if($rid<=0):?>
<div id="recipe" style="display:none">
<?php else: ?>
<div id="recipe">
<?php endif;?>
	<table id="main">
    <tr>
    	<td colspan=3>
        <span id="name"></span>
        <input id="author-recipes" type="button" value="More from Author" />
        </td>
    </tr>
    <tr>
    	<td colspan=3 id="rating_details">
        	<div id="avg_rating">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
                <div></div>
            </div>
        	<span id="ratings_count"></span>
        </td>
    </tr>
    <tr>
    	<td style="width:220px">
        	<div id="photo"></div>
        </td>
        <td>
        	<div id="tags"></div>
            
            <table id="details">
            
            <tr>
            	<td class="details" colspan=3>
                </td>
            </tr>
            <tr>
            	<td class="details">Serving Size</td>
                <td id="yield" colspan=2><input id="serving_size" type="number" min="1" /></td>
            </tr>
            <tr>
                <td class="total_label" class="details">Total Time</td>
                <td id="total"></td>
                <td class="total_label">min</td>
            </tr>
            <tr>   
                <td class="details">Prep</td>
                <td id="prep_time"></td>
                <td>min</td>
            </tr>
            <tr>    
                <td class="details">Inactive</td>
                <td id="inactive_time"></td>
                <td>min</td>
            </tr>
            <tr>   
                <td class="details">Cook</td>
                <td id="cook_time"></td>
                <td>min</td>
            </tr>
            </table>
        </td>
        <td>
        	<div id="options">
                <input type="button" id="favorite" onclick="favorite()" value="Add to Favorites" />
                <input type="button" id="unfavorite" onclick="unfavorite()" value="Remove from Favorites" />
                <input type="hidden" id="recipe_id" value="<?php echo $rid?>" />
                <input type="button" id="delete_recipe" onclick="deleteRecipe()" value="Delete Recipe" />
                <input type="button" class="add_comment" onclick="scrollAndFocus('#comments textarea')" value="Add Comment" />
                <input type="button" id="rate" onclick="rateRecipe()" value="Tried this recipe?" />
                <div id="rate_it">
                	<div></div>
                    <div></div>
                    <div></div>
                    <div></div>
                    <div></div>
                </div>
                <!--<input type="button" id="email" onclick="emailRecipe()" value="Email This Recipe" />-->
            </div><!--options-->
        </td>
    </tr><!--details and photo-->
    <tr>
    	<td colspan=3>
        	<h4>Ingredients</h4>
        	<ul id="ingredients">
            </ul>
        </td>
    </tr><!--ingredients-->
    <tr>
    	<td colspan=3>
        	<h4>Directions</h4>
        	<ol id="directions">
            </ol>
        </td>
    </tr><!--directions-->
    <tr>
    	<td colspan=3>
        	<h4 id="comments_header">Comments (<span></span>)</h4>
            <div id="comments">
            	<textarea maxlength="255"></textarea>
                <span id="charcount"><span>10</span> characters left.</span>
                <input type="button" class="add_comment" value="Post Comment" onclick="addComment()" />
                <ul>
                
                </ul>
            </div>
        </td>
    </tr><!--comments-->
    </table>
</div><!--recipe-->

<script type="text/javascript" src="scripts/recipes.js?<?php echo time();?>"></script>
<script>
// tags
<?php $tags = api("tags/","GET",null);?>
var tempTags = <?php echo $tags;?>;
var tags = new Array();
for(var i=0; i<tempTags.length; i++){
	tags[i] = tempTags[i]['name'];;
}

// ingredients
<?php $ingredients = api("ingredients/","GET",null);?>
var tempIngredients = <?php echo $ingredients;?>;
var ingredients = new Array();
for(var i=0; i<tempIngredients.length; i++){
	ingredients[i] = tempIngredients[i]['name'];;
}

setAutoComplete();
submitOnEnter("#comments textarea",addComment);
characterCount("#comments textarea");
<?php if($rid>0): ?>
getRecipe();
ratingSystem();
<?php endif;?>

// serving size conversion
$("#serving_size").click(function(){ convert(); }).blur(function(){ convert(); });

</script>
<?php require_once("footer.php");?>